<template>
  <div></div>
</template>

<script>
export default {
  props: {
    toolbars: {
      type: Array,
      default: function () {
        return ['delete', 'insertText', 'editText', 'insertImage', 'insertLink', { id: 'insertVideo', name: '插视频', handle: function (select, controller) { return false } }, 'undo', 'cancel']
      }
    },
    upload: {
      type: Object,
      default: function () {
        return {
          server: 'https://huoke.raiseinfo.cn/mycustomer-platform/api/sys/oss/upload',
          compress: true,
          resize: true,
          fileSizeLimit: 10, // 限制文件上传大小为2M
          formName: 'file', // 设置文件name,
          accept: { // accept一般不用设置
            title: 'Files',
            extensions: 'gif,jpg,jpeg,bmp,png,pdf,doc,docx,txt,xls,xlsx,ppt,pptx,zip,mp3,mp4,text,csv',
            mimeTypes: 'image/*,text/*,application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document,application/vnd.ms-excel,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/vnd.ms-powerpoint,application/vnd.openxmlformats-officedocument.presentationml.presentation,application/pdf,application/zip,application/csv'
          }
        }
      }
    }
  },
  data () {
    return {
      editor: null
    }
  },
  methods: {
    getEditor () {
      return this.editor
    }
  },
  created () {
    let that = this
    this.$nextTick(() => {
      /* eslint-disable */
      var editor = new Eleditor({
        el: '#contentEditor',
        mounted: function () {
          var _videoUploader = WebUploader.create({
            auto: true,
            server: 'https://huoke.raiseinfo.cn/mycustomer-platform/api/sys/oss/upload',
            /*按钮类就是[Eleditor-你的自定义按钮id]*/
            pick: $('.Eleditor-insertVideo'),
            duplicate: true,
            resize: false,
            formName: 'file', // 设置文件name,
            fileVal: 'file',
            accept: {
              title: 'Files',
              extensions: 'mp4',
              mimeTypes: 'video/mp4'
            },

          });
          _videoUploader.on('uploadStart', function (_file, _percentage) {
            that.$toast.loading()
          });

          _videoUploader.on('uploadProgress', function (_file, _percentage) {
            // 传输过程中可以做的事情
          });


          _videoUploader.on('uploadSuccess', function (_file, _call) {
            console.log(_file)
            console.log(_call)

            // if (_call.status == 0) {
            //   return window.alert(_call.msg);
            // }

            if (_call.code && _call.code == 0) {
              return window.alert(_call.msg);
            }

            if (_call.code && _call.code == 500) {
              return window.alert(_call.msg);
            }

            /*保存状态，以便撤销*/
            editor.saveState();
            editor.getEditNode().after(`
									<div class='Eleditor-video-area'>
                    <video controls="controls" autoplay="autoplay">
                      <source src="${_call.url}" type="video/mp4">
                    </video>
									</div>
								`);
            editor.hideEditorControllerLayer();
            that.$toast.clear()
          });
        },
        toolbars: this.toolbars,
        upload: this.upload
      })
      this.editor = editor
    })
  },
  destroyed () {
    this.editor.destory()
  }
}
</script>

<style scoped>
</style>
